<?php
/**
 * Created by PhpStorm.
 * TpUser: Laiguiming
 * Date: 2017/6/21 0021
 * Time: 16:52
 */

namespace app\home\controller;

use think\Controller;

class Base extends Controller
{
    //当任何函数加载时候  会调用此函数
    public function _initialize()
    {//默认的方法  会自动执行 特征有点像构造方法

    }

    /**
     * 应答失败
     * @param string $data
     * @param string $msg
     * @return array
     */
    protected function  resError($data='',$msg=''){
        $res=array("rc"=>1,"data"=>$data,"msg"=>$msg);
        echo json_encode($res);
    }

    /**
     * 应答成功
     * @param string $data
     * @param string $msg
     * @return array
     */
    protected function  resSuccess($data='',$msg=''){
        $res=array("rc"=>0,"data"=>$data,"msg"=>$msg);
        echo json_encode($res);
    }

    /**
     * 简单应答
     * @param bool $flag
     * @return array
     */
    protected function resData($flag=true){
        if($flag){
            return $this->resSuccess();
        }else{
            return $this->resError();
        }
    }

}